09. Servers-File Structure Hierarchy

Server + Project Folder Hierarchy

Servers-File Structure Hierarchy

ND#0001 C3 L02 A08 Server + Project Folder Hierarchy Demo

Example Explanation

All of the files pictured above are included in the projects main folder, which is often referred to as the project 'root'. After making sure your project folders are setup in this way, the only thing you need to do is write one line of code in the server.js file that points the server code to the folder that has the index.html and any additional pages. In the example above the name of that folder is website, so in the server.js file the following line of code needs to be added:

app.use(express.static('website'));

This line of code connects our server-side code (the code in the server.js file) to our client-side code (the browser code written in the files housed in the website folder).

Server-Client Code Quiz

QUESTION:

Assume you are writing server-side code in a file that is inside the root directory with another folder named 'public'. What line of code would you write in your server file to point your app to use that folder?

SOLUTION:

NOTE: The solutions are expressed in RegEx pattern. Udacity uses these patterns to check the given answer

Server Summary

In this lesson, we covered how to create a server to run a web app locally in your browser, and to setup the ability to pass code between different parts of a web app through routes. We also covered the folder structure for web apps with an Express server. We will cover routes in the next lesson.

Server Further Research

More on Express servers

For more information on Express you can visit their website, or see this basic example of an Express server.